package com.wuliu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.entity.BasCust;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.domain.BasEmployee;
import com.wuliu.system.mapper.BasEmployeeMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author realue
 * @version 1.0
 * @date 2023-11-05 19:20
 */
@RestController
@RequestMapping("/applet/employee")
@Api(tags = {"员工控制器"})
public class BasEmployeeController {
    @Resource
    private BasEmployeeMapper basEmployeeMapper;

    @GetMapping("/getDrivers")
    @ApiOperation(value = "查询司机列表")
    @ApiImplicitParam(name = "key", value = "关键字(司机电话/姓名)", dataType = "String", paramType = "query")
    public ApiResult<List<BasEmployee>> getDrivers(String key) {
        BasCust cust = SecurityUtils.getBasCust();
        LambdaQueryWrapper<BasEmployee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BasEmployee::getSysAccount, cust.getSysAccount())
                .eq(BasEmployee::getEmpType, 2)
                .eq(BasEmployee::getStatus, 1);
        if (StringUtils.isNotEmpty(key)) {
            wrapper.and(wq -> wq.eq(BasEmployee::getEmpNo, key).or()
                    .eq(BasEmployee::getMobile, key));
        }
        return ApiResult.success(basEmployeeMapper.selectList(wrapper));
    }
}
